package cn.edu.sgu.www.mhxysy.feign.clients.pms;

import cn.edu.sgu.www.mhxysy.dto.system.*;
import cn.edu.sgu.www.mhxysy.easyui.component.impl.Tree;
import cn.edu.sgu.www.mhxysy.entity.system.*;
import cn.edu.sgu.www.mhxysy.feign.clients.FeignService;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.vo.system.MenuVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * 权限平台feign接口
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@FeignClient(name = "pms", fallback = PmsFeignFallback.class)
public interface PmsFeignService extends FeignService {

    // email
    @RequestMapping(path = "/email/enable", method = RequestMethod.POST)
    JsonResult<Void> enable(@RequestParam Integer id);

    @RequestMapping(path = "/email/insert", method = RequestMethod.POST)
    JsonResult<Void> insertEmail(EmailDTO emailDTO);

    @RequestMapping(path = "/email/deleteById", method = RequestMethod.POST)
    JsonResult<Void> deleteEmailById(@RequestParam("id") Integer id);

    @RequestMapping(path = "/email/updateById", method = RequestMethod.POST)
    JsonResult<Void> updateEmailById(EmailDTO emailDTO);

    @RequestMapping(value = "/email/selectByUserId", method = RequestMethod.GET)
    JsonResult<List<Email>> selectEmailsByUserId(@RequestParam("userId") String userId);

    // permission
    @RequestMapping(value = "/permission/resources", method = RequestMethod.POST)
    JsonResult<Void> resources(PermissionInitDTO permissionInitDTO);

    @RequestMapping(value = "/permission/selectPermissions", method = RequestMethod.GET)
    JsonResult<List<Permission>> selectPermissions(@RequestParam("service") String service);

    @RequestMapping(value = "/permission/selectAnonymityPermissions", method = RequestMethod.GET)
    JsonResult<List<String>> selectAnonymityPermissions(@RequestParam("service") String service);

    @RequestMapping(value = "/permission/selectUserPermissions", method = RequestMethod.GET)
    JsonResult<List<String>> selectUserPermissions(
            @RequestParam("username") String username,
            @RequestParam("service") String service
    );

    // user
    @RequestMapping(value = "/user/lock", method = RequestMethod.POST)
    JsonResult<Void> lockUser(@RequestParam("userId") String userId);

    @RequestMapping(value = "/user/updatePass", method = RequestMethod.POST)
    JsonResult<Void> updatePass(UserPassUpdateDTO userPassUpdateDTO);

    @RequestMapping(value = "/user/updateByUsername", method = RequestMethod.POST)
    JsonResult<Void> updateByUsername(User user, @RequestParam("service") String service);

    /**
     * 修改用户最后一次登录时间
     * @param userId 用户ID
     * @param lastLoginTime 登录时间
     * @return JsonResult<Void>
     */
    @PostMapping("/user/updateLastLoginTime")
    JsonResult<Void> updateLastLoginTime(
            @RequestParam("userId") String userId,
            @RequestParam("lastLoginTime") LocalDateTime lastLoginTime
    );

    @RequestMapping(value = "/user/selectByUsername", method = RequestMethod.GET)
    JsonResult<User> selectByUsername(
            @RequestParam("username") String username,
            @RequestParam("service") String service
    );

    // user_menu
    @RequestMapping(value = "/user_menu/display", method = RequestMethod.POST)
    JsonResult<Void> control(MenuTreeDTO menuTreeDTO);

    @RequestMapping(value = "/user_menu/updateSort", method = RequestMethod.POST)
    JsonResult<Void> updateSort(UserMenuDTO userMenuDTO);

    @RequestMapping(value = "/user_menu/getLeftMenu", method = RequestMethod.GET)
    JsonResult<List<MenuVO>> getLeftMenu(@RequestParam("userId") String userId);

    @SuppressWarnings("all")
    @RequestMapping(value = "/user_menu/getMenuTree", method = RequestMethod.GET)
    JsonResult<List<Tree>> getMenuTree(@RequestParam("userId") String userId);

    // user_role
    @RequestMapping(value = "/user_role/selectUserRoles", method = RequestMethod.GET)
    JsonResult<Set<String>> selectUserRoles(
            @RequestParam("username") String username,
            @RequestParam("service") String service
    );

    // table
    @RequestMapping(value = "/table/getTableNames", method = RequestMethod.GET)
    JsonResult<List<String>> getTableNames(@RequestParam("databaseName") String databaseName);

    @RequestMapping(value = "/table/selectByDatabase", method = RequestMethod.GET)
    JsonResult<List<Table>> selectByDatabase(@RequestParam("databaseName") String databaseName);

    // table_field
    @RequestMapping(value = "/table_field/selectFields", method = RequestMethod.GET)
    JsonResult<List<TableField>> selectFields(@RequestParam("tableName") String tableName);
}